package com.base.log.controller;

import java.util.List;
import java.util.Arrays;

import com.base.common.annotation.Log;
import com.base.common.annotation.RepeatSubmit;
import com.base.common.core.controller.BaseController;
import com.base.common.core.domain.PageQuery;
import com.base.common.core.domain.R;
import com.base.common.core.page.TableDataInfo;
import com.base.common.core.validate.AddGroup;
import com.base.common.core.validate.EditGroup;
import com.base.common.enums.BusinessType;
import com.base.common.utils.poi.ExcelUtil;
import com.base.log.domain.bo.TSysLogBo;
import com.base.log.domain.vo.TSysLogVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.base.log.service.ITSysLogService;

/**
 * 操作日志
 *
 * @author base
 * @date 2023-10-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/log/sysLog")
public class TSysLogController extends BaseController {

    private final ITSysLogService iTSysLogService;

    /**
     * 查询操作日志列表
     */
// @SaCheckPermission("log:sysLog:list")
    @GetMapping("/list")
    public R<TableDataInfo<TSysLogVo>> list(TSysLogBo bo, PageQuery pageQuery) {
        return R.ok(iTSysLogService.queryPageList(bo, pageQuery));
    }

    /**
     * 导出操作日志列表
     */
    //   @SaCheckPermission("log:sysLog:export")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TSysLogBo bo, HttpServletResponse response) {
        List<TSysLogVo> list = iTSysLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "操作日志", TSysLogVo.class, response);
    }

    /**
     * 获取操作日志详细信息
     *
     * @param logId 主键
     */
    //    @SaCheckPermission("log:sysLog:query")
    @GetMapping("/{logId}")
    public R<TSysLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String logId) {
        return R.ok(iTSysLogService.queryById(logId));
    }

    /**
     * 新增操作日志
     */
//     @SaCheckPermission("log:sysLog:add")
    @Log(title = "操作日志", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TSysLogBo bo) {
        return toAjax(iTSysLogService.insertByBo(bo));
    }

    /**
     * 修改操作日志
     */
    //   @SaCheckPermission("log:sysLog:edit")
    @Log(title = "操作日志", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TSysLogBo bo) {
        return toAjax(iTSysLogService.updateByBo(bo));
    }

    /**
     * 删除操作日志
     *
     * @param logIds 主键串
     */
    //  @SaCheckPermission("log:sysLog:remove")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] logIds) {
        return toAjax(iTSysLogService.deleteWithValidByIds(Arrays.asList(logIds), true));
    }
}
